package br.com.servlet.controller;

import java.util.Calendar;
import java.util.TimerTask;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.robot.RobotController;
import br.com.robot.agenda.Agendador;
import br.com.robot.implement.nuuvem.Nuuvem;

@Controller
public class NuuvemController 
{
	RobotController m_Controller = RobotController.infController( );
	
	long m_time_interval = ( ( ( 60 ) * 60 ) * 24 );
	
	public NuuvemController( )
	{
		Calendar instance = Calendar.getInstance( );
		
		instance.set( Calendar.AM_PM,        Calendar.AM                                   );
		instance.set( Calendar.DAY_OF_MONTH, ( instance.get( Calendar.DAY_OF_MONTH ) + 1 ) );
		instance.set( Calendar.HOUR,         0                                             );
		instance.set( Calendar.MINUTE,       0                                             );
		instance.set( Calendar.SECOND,       0                                             );
		
		Agendador.agendar( new TimerTask( )
		{
			@Override
			public void run( )
			{
				m_Controller.executa( Nuuvem.class );
			}
		}, instance, m_time_interval );
	}
	
	@RequestMapping("/nuuvem-executaRobo")
	public String executaRobo( Model model )
	{
//		if( m_Controller.getStatus( Nuuvem.class ) == null ) 
			m_Controller.executa( Nuuvem.class );
		
//		model.addAttribute( "resposta", RobotsUtils.validarStatus( Nuuvem_Games.class ) );
		
		return "resposta";
	}
	
	@RequestMapping("/nuuvem-verificaRobo")
	public String verificaRobo( Model model )
	{
//		model.addAttribute( "resposta", RobotsUtils.validarStatus( Nuuvem_Games.class ) );
		
		return "resposta";
	}
}